﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsFormsApplication3
{
    public partial class MERCHANDISING : Form

    {
        Transaction.MerchandisingTransaction mtransctn = null;
        public MERCHANDISING()
        {
            InitializeComponent();
            mtransctn = new Transaction.MerchandisingTransaction();
        }

        private void oleDbConnection1_InfoMessage(object sender, System.Data.OleDb.OleDbInfoMessageEventArgs e)
        {

        }
        /// <summary>
        /// validates the controls and return true if all
        /// cantents are properly entered
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean validatecontrols()
        {
            Boolean sucess = false;
            if (cmbvia.Text == null || cmbvia.Text.Trim() == "")
            {
                lblstatus.Text = "SELECT MODE OF COMMUNICATION";
                cmbvia.Focus();


            }
            else if (cmbto.Text == null || cmbto.Text.Trim() == "")
            {
                lblstatus.Text = "SELECT THE PERSON YOU CONTACTED";
                cmbvia.Focus();
            }
            else if (txtfor.Text == null || txtfor.Text.Trim() == "")
            {
                lblstatus.Text = "MENTION THE PURPOSE";
                txtfor.Focus();
            }
            else if (txtfor.Text == null || txtfor.Text.Trim() == "")
            {
                lblstatus.Text = "MENTION THE PURPOSE";
                txtfor.Focus();
            }
            else if (txtname.Text == null || txtname.Text.Trim() == "")
            {
                lblstatus.Text = "MENTION THE PERSON OR COMPANY CONTACTED";
                txtname.Focus();
            }

            else
            {
                sucess = true;
            }

            return sucess;

        }

        public void getmerchandisedata()
        {
            if(validatecontrols()){
            ArrayList arrylist = new ArrayList();
           
            arrylist.Add(DateTime.Now.Date);
               
            
            arrylist.Add(cmbvia.Text);
            arrylist.Add(cmbto.Text);
            arrylist.Add(txtfor.Text);
            arrylist.Add(txtname.Text);
            arrylist.Add(rhtresult.Text);
              arrylist.Add(DateTime.Now.ToLongTimeString()); 
            if (arrylist.Count != 0)
            {

                try
                {
                    mtransctn.insertmerchandisedata(arrylist);
                }
                catch (Exception exp)
                {

                    MessageBox.Show(exp.ToString());
                }
            }
            }
        }

        private void MERCHANDISING_Load(object sender, EventArgs e)
        {
            cmbto.SelectedIndex = 0;
            cmbvia.SelectedIndex = 0;
            
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            getmerchandisedata();
            clearcontrols();
        }

        public void clearcontrols()
        {
            cmbto.SelectedIndex = 0;
            cmbvia.SelectedIndex = 0;
            txtname.Text = "";

                txtfor.Text="";
                rhtresult.Text = "";
                lblstatus.Text = "Customer is King";

        }

      
    }
}
